﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace AFCEPF.BankApplication.BLL
{
    public class AccountList2<TAccount> : ReadOnlyCollection<TAccount> where TAccount : AccountBase
    {
        public AccountList2() : base(new List<TAccount>())
        {}

        /// <summary>
        /// Creates the specified account.
        /// </summary>
        /// <param name="customer">The customer.</param>
        /// <param name="deposit">The deposit.</param>
        /// <returns>the specified account</returns>
        public TAccount Create(Customer customer, double deposit)
        {
            TAccount result = (TAccount)AccountFactory.CreateAccount(customer, deposit);


            // Let's wire the newly created Account's events
            // to event handlers in the Bank class.
            result.NegativeBalanceWithdraw      += Bank.Instance.OnAccountNegativeBalanceWithdraw;
            result.OverLimitWithdraw            += Bank.Instance.OnOverLimitWithdraw;

            this.Items.Add(result);
            
            return result;
        }

        /// <summary>
        /// Supprime tous les éléments 
        /// de la  liste
        /// </summary>        
        public void Clear()
        {
            Items.Clear();
        }




    }
}
